package org.example.managementsystem.service;

import org.example.managementsystem.model.DeviceRepair;
import org.example.managementsystem.repository.DeviceRepairDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备报修服务层
 * @author 王振祎
 * @date 2025-05-21
 */
@Service
public class DeviceRepairService {
    private final DeviceRepairDao deviceRepairDao;

    @Autowired
    public DeviceRepairService(DeviceRepairDao deviceRepairDao) {
        this.deviceRepairDao = deviceRepairDao;
    }

    /**
     * 提交设备报修
     */
    public void submitRepair(
            String deviceNumber,
            String repairDesc,
            String applicantJobNumber) {

        // 创建报修对象,更新报修表
        DeviceRepair repair = new DeviceRepair();
        repair.setDeviceNumber(deviceNumber);
        repair.setRepairDesc(repairDesc);
        repair.setApplicantJobNumber(applicantJobNumber);
        repair.setIsApproved(false);
        repair.setStatus(false);

        deviceRepairDao.insertRepair(repair);
    }

    public void submitRepair(DeviceRepair repair){
        deviceRepairDao.insertRepair(repair);
    }

    /**
     * 更新报修状态
     */
    public void updateRepair(DeviceRepair repair) {
        deviceRepairDao.updateRepair(repair);
    }

    /**
     * 获取所有报修
     */
    public List<DeviceRepair> getAllRepairs() {
        return deviceRepairDao.getAllRepairs();
    }

    /**
     * 获取所有未审核的报修
     */
    public List<DeviceRepair> getAllUnreviewedRepairs() {
        return deviceRepairDao.getAllUnreviewedRepairs();
    }

    /**
     * 根据ID获取报修
     */
    public DeviceRepair getRepairById(int repairId) {
        return deviceRepairDao.getRepairById(repairId);
    }

    /**
     * 根据用户ID获取报修记录
     */
    public List<DeviceRepair> getRepairByUserId(int userId) {
        return deviceRepairDao.getRepairByUserId(userId);
    }

    /**
     * 根据设备ID获取报修记录
     */
    public List<DeviceRepair> getRepairByDeviceId(int deviceId) {
        return deviceRepairDao.getRepairByDeviceId(deviceId);
    }

    /**
     * 根据Id删除报修
     */
    public void deleteRepair(int repairId) {
        deviceRepairDao.deleteRepair(repairId);
    }
}